home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0586.arc
/
FILLING4.LTG
< prev
next >
Wrap
Text File
|
1986-04-06
|
3KB
|
70 lines
Listing 4
An extremely efficient seed filling algorithm.
procedure Fill(x,y,NewColor: Integer);
var
EraseColor,StartLeftx,StartRightx,i: Integer;
procedure RecursiveFill(Leftx,Rightx,y,ParentLeftx,ParentRightx,
Direction: Integer);
var
NextLeftx, NextRightx: Integer;
begin {of procedure RecursiveFill}
NextLeftx := Leftx; {start at leftmost point in shadow}
Repeat {search for run in current shadow}
if PD(NextLeftx,y)=EraseColor {find next leftmost x}
then
begin
NextRightx := NextLeftx;
while PD(NextLeftx-1,y)=EraseColor do
NextLeftx := NextLeftx-1;
end
else
begin
NextLeftx := NextLeftx + 1;
while (PD(NextLeftx,y)<>EraseColor) and (NextLeftx <= Rightx) do
NextLeftx := NextLeftx+1;
NextRightx := NextLeftx;
end;
if NextLeftx <= Rightx {find next rightmost x}
then
begin
while PD(NextRightx+1,y)=EraseColor do
NextRightx := NextRightx + 1;
for i := NextLeftx to NextRightx do {fill current run}
DP(i,y,NewColor);
RecursiveFill(NextLeftx,NextRightx,y-Direction,NextLeftx,
NextRightx,Direction); {call fill algorithm}
if NextLeftx <= ParentLeftx - 2 {with valid shadows}
then RecursiveFill(NextLeftx,ParentLeftx-2,y+Direction,NextLeftx,
NextRightx,-Direction);
if ParentRightx + 2 <= NextRightx
then RecursiveFill(ParentRightx+2,NextRightx,y+Direction,NextLeftx,
NextRightx,-Direction);
NextLeftx := NextRightx + 2; {skip to next possible leftmost x}
end;
Until NextLeftx > Rightx; {repeat until entire shadow examined}
end; {of procedure RecursiveFill}
begin {of procedure Fill}
EraseColor := PD(x,y); {record color of seed point}
if EraseColor = NewColor then exit; {already done}
if EraseColor = -1 then exit; {seed point is off screen}
StartLeftx := x; {find leftmost x in starting run}èwhile PD(StartLeftx-1,y)=EraseColor do
StartLeftx := StartLeftx - 1;
StartRightx := x; {find rightmost x in starting run}
while PD(StartRightx+1,y)=EraseColor do
StartRightx := StartRightx + 1;
for i := StartLeftx to StartRightx do {fill starting span}
DP(i,y,NewColor);
RecursiveFill(StartLeftx,StartRightx,y-1,StartLeftx,
StartRightx,+1); {examine shadows of run}
RecursiveFill(StartLeftx,StartRightx,y+1,StartLeftx,
StartRightx,-1);
end; {of procedure Fill}